<template>
  <div class="multi-round-qa-container">
    <!-- 左侧历史问答记录 -->
    <aside class="history-sidebar">
      <div class="sidebar-header">
        <h2>对话历史</h2>
        <button class="new-chat-btn" @click="handleNewChat">
          <i class="el-icon-plus"></i>
          <span>新建对话</span>
        </button>
      </div>

      <div class="conversation-list">
        <div v-if="conversations.length === 0" class="empty-state">
          <el-empty description="暂无对话记录" :image-size="80" />
        </div>
        <template v-else>
          <div
            v-for="conversation in conversations"
            :key="conversation.id"
            class="conversation-item"
            :class="{ active: currentConversationId === conversation.id }"
            @click="selectConversation(conversation.id)"
          >
            <div class="conversation-info">
              <div class="conversation-title">
                {{ conversation.name || "新对话" }}
              </div>
              <div class="conversation-time">
                {{ formatTime(conversation.created_at) }}
              </div>
            </div>
          
          </div>
        </template>
      </div>
    </aside>

    <!-- 右侧聊天区域 -->
    <div class="chat-area">
      <!-- 聊天头部 -->
      <div class="chat-header">
        <h2>{{ currentConversationName || "智能多轮问答" }}</h2>
        <div class="header-actions">
          <el-button size="small" type="info" plain @click="clearChat">
            <i class="el-icon-delete"></i>
            清空对话
          </el-button>
        </div>
      </div>

      <!-- 聊天消息区域 -->
      <div class="chat-messages" ref="messagesContainer">
        <!-- 欢迎消息 -->
        <div v-if="messages.length === 0" class="welcome-message">
          <div class="welcome-icon">💬</div>
          <h3>欢迎使用智能多轮问答系统</h3>
          <p>我可以帮你解答各类问题，支持多轮对话，上下文理解能力强</p>
          <div class="welcome-tips">
            <div class="tip-item">
              <i class="el-icon-check"></i>
              <span>支持连续提问</span>
            </div>
            <div class="tip-item">
              <i class="el-icon-check"></i>
              <span>智能上下文理解</span>
            </div>
            <div class="tip-item">
              <i class="el-icon-check"></i>
              <span>实时回复反馈</span>
            </div>
          </div>
          
          <!-- 快捷问题 -->
          <div class="quick-questions">
            <h4 class="quick-title">快捷问题</h4>
            <div class="question-grid">
              <div 
                class="question-card" 
                v-for="(question, index) in quickQuestions" 
                :key="index"
                @click="handleQuickQuestion(question)"
              >
                <i :class="question.icon"></i>
                <span>{{ question.text }}</span>
              </div>
            </div>
          </div>
        </div>

        <!-- 对话消息列表 -->
        <template v-for="(msg, index) in messages" :key="index">
          <!-- 用户消息 -->
          <div class="message-wrapper user-message">
            <div class="message-avatar user-avatar">
              <i class="el-icon-user"></i>
            </div>
            <div class="message-content">
              <div class="message-text">{{ msg.question }}</div>
              <div class="message-time">{{ formatMessageTime(msg.timestamp) }}</div>
            </div>
          </div>

          <!-- AI回复 -->
          <div class="message-wrapper ai-message">
            <div class="message-avatar ai-avatar">
              <i class="el-icon-chat-dot-round"></i>
            </div>
            <div class="message-content">
              <div class="message-text" v-html="formatMarkdown(msg.answer)"></div>
              <div class="message-time">{{ formatMessageTime(msg.timestamp) }}</div>
              <div class="message-actions">
                <button class="action-btn" @click="copyText(msg.answer)" title="复制">
                  <i class="el-icon-document-copy"></i>
                </button>
                <button class="action-btn" title="点赞">
                  <i class="el-icon-thumb"></i>
                </button>
              </div>
            </div>
          </div>
        </template>

        <!-- 加载中状态 -->
        <div v-if="isLoading" class="message-wrapper ai-message loading-wrapper">
          <div class="message-content loading">
            <div class="loading-row">
              <div class="typing-indicator">
                <span></span>
                <span></span>
                <span></span>
              </div>
              <span class="loading-text">AI正在思考中...</span>
              <span class="message-time loading-time">{{ formatMessageTime(new Date().toISOString()) }}</span>
            </div>
          </div>
        </div>
      </div>

      <!-- 输入区域 -->
      <div class="chat-input-wrapper">
        <div class="input-container">
          <textarea
            v-model="inputMessage"
            placeholder="请输入您的问题，支持多轮对话..."
            @keydown.enter.exact.prevent="handleSend"
            @input="autoResize"
            ref="textareaRef"
            :disabled="isLoading"
            rows="1"
          ></textarea>
          <button
            class="send-btn"
            @click="handleSend"
            :disabled="!inputMessage.trim() || isLoading"
          >
            <i v-if="!isLoading" class="el-icon-s-promotion"></i>
            <i v-else class="el-icon-loading"></i>
          </button>
        </div>
        <div class="input-tips">
          <span>按 Enter 发送，Shift + Enter 换行</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted, nextTick, computed } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import axios from "axios";
import MarkdownIt from "markdown-it";

// Markdown 渲染器
const md = new MarkdownIt({
  html: true,
  linkify: true,
  typographer: true,
});

// 数据状态
const conversations = ref([]);
const currentConversationId = ref(null);
const currentConversationName = ref("");
const messages = ref([]);
const inputMessage = ref("");
const isLoading = ref(false);
const messagesContainer = ref(null);
const textareaRef = ref(null);

// 快捷问题
const quickQuestions = ref([
  { text: "智能生成简历", icon: "el-icon-edit" },
  { text: "验证学历", icon: "el-icon-document" },
  { text: "什么是人工智能？", icon: "el-icon-search" },
  { text: "给我讲个编程笑话", icon: "el-icon-chat-line-round" },
  { text: "如何提高代码质量？", icon: "el-icon-star-off" },
  { text: "推荐一些学习资源", icon: "el-icon-reading" },
]);

// 获取对话列表
const fetchConversations = async () => {
  try {
    const token = localStorage.getItem("token");
    const response = await axios.get(
      `http://localhost:8000/chat/list_session/`,
      {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );
    if (response.data.code === 1) {
      // 适配后端返回的数据结构
      const sessions = response.data.data.sessions || [];
      conversations.value = sessions.map((session) => ({
        id: session.session_id,
        name: session.last_message || "新对话",
        created_at: session.create_time,
        session_id: session.session_id,
      }));
    }
  } catch (error) {
    console.error("获取对话列表失败:", error);
    ElMessage.error("获取对话列表失败");
  }
};

// 创建新对话
const handleNewChat = async () => {
  try {
    const token = localStorage.getItem("token");
    const response = await axios.post(
      "http://localhost:8000/chat/create_session/",
      {},
      {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );
    if (response.data.code === 1) {
      currentConversationId.value = response.data.data.session_id;
      currentConversationName.value = "新对话";
      messages.value = [];
      await fetchConversations();
      ElMessage.success("创建新对话成功");
    } else {
      ElMessage.error(response.data.message || "创建对话失败");
    }
  } catch (error) {
    console.error("创建对话失败:", error);
    ElMessage.error("创建对话失败");
  }
};

// 选择对话
const selectConversation = async (id) => {
  currentConversationId.value = id;
  try {
    const token = localStorage.getItem("token");
    const response = await axios.get(
      `http://localhost:8000/chat/session_message/`,
      {
        params: {
          session_id: id,
        },
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );
    if (response.data.code === 1) {
      // 转换消息格式：将 role-content 格式转换为 question-answer 格式
      const messagesList = response.data.data.messages || [];
      const formattedMessages = [];
      
      for (let i = 0; i < messagesList.length; i += 2) {
        const userMsg = messagesList[i];
        const assistantMsg = messagesList[i + 1];
        
        if (userMsg && userMsg.role === "user") {
          formattedMessages.push({
            question: userMsg.content,
            answer: assistantMsg && assistantMsg.role === "assistant" ? assistantMsg.content : "",
            timestamp: new Date().toISOString(),
          });
        }
      }
      
      messages.value = formattedMessages;
      const conversation = conversations.value.find((c) => c.id === id);
      currentConversationName.value = conversation?.name || "对话";
      scrollToBottom();
    } else {
      ElMessage.error(response.data.message || "获取对话消息失败");
    }
  } catch (error) {
    console.error("获取对话消息失败:", error);
    ElMessage.error("获取对话消息失败");
  }
};

// 删除对话
const deleteConversation = async (id) => {
  try {
    await ElMessageBox.confirm("确定要删除这个对话吗？", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    });

    const response = await axios.delete(
      `http://127.0.0.1:8000/chat/conversations/${id}/`
    );
    if (response.data.code === 200) {
      ElMessage.success("删除成功");
      if (currentConversationId.value === id) {
        currentConversationId.value = null;
        currentConversationName.value = "";
        messages.value = [];
      }
      await fetchConversations();
    }
  } catch (error) {
    if (error !== "cancel") {
      console.error("删除对话失败:", error);
      ElMessage.error("删除对话失败");
    }
  }
};

// 清空当前对话
const clearChat = async () => {
  if (!currentConversationId.value) {
    ElMessage.warning("请先选择一个对话");
    return;
  }

  try {
    await ElMessageBox.confirm("确定要清空当前对话吗？", "提示", {
      confirmButtonText: "确定",
      cancelButtonText: "取消",
      type: "warning",
    });

    messages.value = [];
    ElMessage.success("清空成功");
  } catch (error) {
    // 用户取消
  }
};

// 发送消息
const handleSend = async () => {
  if (!inputMessage.value.trim() || isLoading.value) return;

  // 如果没有当前对话，先创建
  if (!currentConversationId.value) {
    await handleNewChat();
    // 等待创建完成后再发送消息
    if (!currentConversationId.value) {
      ElMessage.error("创建对话失败，请重试");
      return;
    }
  }

  const question = inputMessage.value.trim();
  inputMessage.value = "";
  resetTextareaHeight();

  // 添加用户消息
  messages.value.push({
    question: question,
    answer: "",
    timestamp: new Date().toISOString(),
  });

  scrollToBottom();
  isLoading.value = true;

  try {
    const token = localStorage.getItem("token");
    const response = await axios.post(
      "http://localhost:8000/chat/send_message/",
      {
        session_id: currentConversationId.value,
        question: question,
      },
      {
        headers: {
          Authorization: `Bearer ${token}`,
        },
      }
    );

    if (response.data.code === 1) {
      const answer = response.data.data.reply || "抱歉，我暂时无法回答这个问题";
      
      // 更新最后一条消息的答案
      messages.value[messages.value.length - 1].answer = answer;

      // 如果是第一条消息，更新对话名称
      if (messages.value.length === 1) {
        currentConversationName.value = question.substring(0, 20) + (question.length > 20 ? "..." : "");
        await fetchConversations();
      }
    } else {
      messages.value[messages.value.length - 1].answer = "抱歉，获取回答失败，请重试";
      ElMessage.error(response.data.message || "获取回答失败");
    }
  } catch (error) {
    console.error("发送消息失败:", error);
    messages.value[messages.value.length - 1].answer = "抱歉，网络错误，请稍后重试";
    ElMessage.error("发送消息失败");
  } finally {
    isLoading.value = false;
    scrollToBottom();
  }
};

// 自动调整输入框高度
const autoResize = () => {
  nextTick(() => {
    if (textareaRef.value) {
      textareaRef.value.style.height = "auto";
      textareaRef.value.style.height = Math.min(textareaRef.value.scrollHeight, 150) + "px";
    }
  });
};

// 重置输入框高度
const resetTextareaHeight = () => {
  if (textareaRef.value) {
    textareaRef.value.style.height = "auto";
  }
};

// 滚动到底部
const scrollToBottom = () => {
  nextTick(() => {
    if (messagesContainer.value) {
      messagesContainer.value.scrollTop = messagesContainer.value.scrollHeight;
    }
  });
};

// 格式化 Markdown
const formatMarkdown = (text) => {
  if (!text) return "";
  return md.render(text);
};

// 复制文本
const copyText = (text) => {
  navigator.clipboard.writeText(text).then(
    () => {
      ElMessage.success("复制成功");
    },
    () => {
      ElMessage.error("复制失败");
    }
  );
};

// 处理快捷问题点击
const handleQuickQuestion = async (question) => {
  // 如果是验证学历，弹出输入框让用户输入验证码
  if (question.text === "验证学历") {
    try {
      const { value: verificationCode } = await ElMessageBox.prompt(
        "请输入您的学历验证码",
        "学历验证",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          inputPattern: /^.+$/,
          inputErrorMessage: "验证码不能为空",
          inputPlaceholder: "请输入学历验证码",
        }
      );
      
      if (verificationCode && verificationCode.trim()) {
        // 将验证码和问题一起发送
        inputMessage.value = `${question.text}，验证码：${verificationCode.trim()}`;
        nextTick(() => {
          handleSend();
        });
      }
    } catch (error) {
      // 用户取消了输入
      console.log("用户取消了学历验证");
    }
  } else {
    // 其他快捷问题直接发送
    inputMessage.value = question.text;
    nextTick(() => {
      handleSend();
    });
  }
};

// 格式化时间
const formatTime = (timestamp) => {
  if (!timestamp) return "";
  const date = new Date(timestamp);
  const now = new Date();
  const diff = now - date;

  if (diff < 60000) return "刚刚";
  if (diff < 3600000) return Math.floor(diff / 60000) + "分钟前";
  if (diff < 86400000) return Math.floor(diff / 3600000) + "小时前";
  if (diff < 604800000) return Math.floor(diff / 86400000) + "天前";

  return date.toLocaleDateString();
};

const formatMessageTime = (timestamp) => {
  if (!timestamp) return "";
  const date = new Date(timestamp);
  return date.toLocaleTimeString("zh-CN", {
    hour: "2-digit",
    minute: "2-digit",
  });
};

// 页面挂载
onMounted(() => {
  fetchConversations();
});
</script>

<style scoped>
.multi-round-qa-container {
  display: flex;
  height: calc(100vh - 49px);
  margin-top: 49px;
  background: linear-gradient(to bottom, #f5f7fa 0%, #ffffff 100%);
}

/* 左侧历史记录 */
.history-sidebar {
  width: 300px;
  min-width: 300px;
  background: #fff;
  border-right: 1px solid #e8eaed;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid #e8eaed;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.sidebar-header h2 {
  margin: 0 0 16px 0;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}

.new-chat-btn {
  width: 100%;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.3s ease;
}

.new-chat-btn:hover {
  background: rgba(255, 255, 255, 0.3);
  transform: translateY(-2px);
}

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.conversation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid transparent;
}

.conversation-item:hover {
  background: #f5f7fa;
  border-color: #e8eaed;
}

.conversation-item.active {
  background: linear-gradient(135deg, #e3f2fd 0%, #f3e5f5 100%);
  border-color: #667eea;
}

.conversation-info {
  flex: 1;
  min-width: 0;
}

.conversation-title {
  font-size: 14px;
  font-weight: 500;
  color: #333;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-time {
  font-size: 12px;
  color: #999;
}

.delete-btn {
  padding: 4px 8px;
  background: none;
  border: none;
  color: #999;
  cursor: pointer;
  border-radius: 4px;
  opacity: 0;
  transition: all 0.3s ease;
}

.conversation-item:hover .delete-btn {
  opacity: 1;
}

.delete-btn:hover {
  background: #fee;
  color: #f56c6c;
}

.empty-state {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 20px;
}

/* 右侧聊天区域 */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid #e8eaed;
  background: #fafbfc;
}

.chat-header h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  background: linear-gradient(to bottom, #fafbfc 0%, #ffffff 100%);
}

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: #666;
}

.welcome-icon {
  font-size: 64px;
  margin-bottom: 20px;
}

.welcome-message h3 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin-bottom: 12px;
}

.welcome-message p {
  font-size: 16px;
  color: #666;
  margin-bottom: 32px;
}

.welcome-tips {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.tip-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f5f7fa;
  border-radius: 20px;
  font-size: 14px;
  color: #667eea;
}

/* 快捷问题 */
.quick-questions {
  margin-top: 48px;
  width: 100%;
  max-width: 800px;
}

.quick-title {
  font-size: 18px;
  font-weight: 600;
  color: #333;
  margin-bottom: 24px;
  text-align: left;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
}

.question-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
  border: 2px solid #e8eaed;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
  position: relative;
  overflow: hidden;
}

.question-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(102, 126, 234, 0.1), transparent);
  transition: left 0.5s ease;
}

.question-card:hover::before {
  left: 100%;
}

.question-card:hover {
  border-color: #667eea;
  background: linear-gradient(135deg, #f5f7ff 0%, #e8ecf8 100%);
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(102, 126, 234, 0.15);
}

.question-card i {
  font-size: 20px;
  color: #667eea;
  flex-shrink: 0;
}

.question-card span {
  font-size: 14px;
  color: #333;
  font-weight: 500;
  line-height: 1.5;
  text-align: left;
}

.question-card:active {
  transform: translateY(-2px);
}

@media (max-width: 768px) {
  .question-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .quick-questions {
    max-width: 100%;
  }
}

.message-wrapper {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.user-avatar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
}

.ai-avatar {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: #fff;
}

.user-message {
  flex-direction: row-reverse;
}

.user-message .message-content {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border-radius: 12px 12px 0 12px;
}

.ai-message .message-content {
  background: #f5f7fa;
  color: #333;
  border-radius: 12px 12px 12px 0;
}

.message-content {
  max-width: 70%;
  padding: 12px 16px;
  position: relative;
}

.message-text {
  line-height: 1.6;
  word-wrap: break-word;
  font-size: 15px;
}

.message-time {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 8px;
}

.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.message-wrapper:hover .message-actions {
  opacity: 1;
}

.action-btn {
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  transition: all 0.3s ease;
}

.action-btn:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

.message-content.loading {
  padding: 16px 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf0 100%);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.85;
  }
}

.loading-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.loading-time {
  margin-left: auto;
  white-space: nowrap;
}

.typing-indicator {
  display: flex;
  gap: 6px;
  align-items: center;
}

.typing-indicator span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  animation: typing 1.4s infinite ease-in-out;
  box-shadow: 0 2px 4px rgba(102, 126, 234, 0.3);
}

.typing-indicator span:nth-child(1) {
  animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0) scale(1);
    opacity: 0.7;
  }
  30% {
    transform: translateY(-12px) scale(1.2);
    opacity: 1;
  }
}

.loading-text {
  font-size: 14px;
  color: #667eea;
  font-weight: 500;
  animation: fadeInOut 2s infinite;
  flex-shrink: 0;
}

@keyframes fadeInOut {
  0%, 100% {
    opacity: 0.6;
  }
  50% {
    opacity: 1;
  }
}

/* 输入区域 */
.chat-input-wrapper {
  border-top: 1px solid #e8eaed;
  background: #fff;
  padding: 16px 24px;
}

.input-container {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: #f5f7fa;
  border-radius: 12px;
  padding: 12px;
  border: 2px solid transparent;
  transition: all 0.3s ease;
}

.input-container:focus-within {
  border-color: #667eea;
  background: #fff;
}

.input-container textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  outline: none;
  font-size: 15px;
  line-height: 1.6;
  font-family: inherit;
  max-height: 150px;
  overflow-y: auto;
}

.input-container textarea::placeholder {
  color: #999;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.send-btn:hover:not(:disabled) {
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.input-tips {
  margin-top: 8px;
  font-size: 12px;
  color: #999;
  text-align: center;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .history-sidebar {
    position: absolute;
    left: -300px;
    z-index: 10;
    transition: left 0.3s ease;
  }

  .history-sidebar.active {
    left: 0;
  }

  .message-content {
    max-width: 85%;
  }
}
</style>

